package club.looli.haoke.api.controller;

import club.looli.haoke.api.service.HouseResourcesService;
import club.looli.haoke.api.vo.TableResult;
import club.looli.haoke.houseResources.api.ApiHouseResourcesService;
import club.looli.haoke.houseResources.entity.HouseResources;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * Created by looli on 2020/7/7
 * </p>
 *
 * <p>
 *
 * </p>
 *
 * @author looli
 * @since 2020/7/7
 */
@RestController
@RequestMapping("house/resources")
public class HouseResourcesController {

    @Autowired
    private HouseResourcesService houseResourcesService;

    /**
     * 保存房源信息
     * @param houseResources
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> save(@RequestBody HouseResources houseResources){
        boolean flag = houseResourcesService.save(houseResources);
        try {
            if (flag){
                return ResponseEntity.status(HttpStatus.CREATED).build();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 查询房源列表
     * @param houseResources
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseEntity<TableResult> list(HouseResources houseResources,
                                            @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return ResponseEntity.ok(houseResourcesService.queryList(houseResources, currentPage, pageSize));
    }

}
